package io.litchi.auth.interfaces.facade;

import io.litchi.auth.Infrastructure.common.command.menupern.MenuPernSaveCommand;
import io.litchi.auth.Infrastructure.common.command.menupern.MenuPernUpdateStatusCommand;
import io.litchi.auth.Infrastructure.common.result.menu.TreeMenuResult;
import io.litchi.auth.application.service.MenuService;
import io.litchi.common.result.Result;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * 菜单 权限模块
 * @author helang
 * @since 2025-11-25
 */
@RestController
@RequestMapping("/menu")
@RequiredArgsConstructor
@Validated
public class MenuFacade {

    private final MenuService menuService;

    /**
     * 树形菜单列表
     * @return treeList
     */
    @PostMapping("/tree/list")
    public Result<List<TreeMenuResult>> treeList(){
        return menuService.treeList();
    }

    /**
     * 保存或编辑
     * @param menuPernSaveCommand menuPernSaveCommand
     * @return void
     */
    @PostMapping("/save")
    public Result<Void> save(@RequestBody  MenuPernSaveCommand menuPernSaveCommand){
        return menuService.save(menuPernSaveCommand);
    }

    /**
     * 详情
     * @param id id
     * @return menuPernSaveCommand
     */
    @GetMapping("/detail/{id}")
    public Result<MenuPernSaveCommand> detail(@PathVariable Long id){
        return menuService.detail(id);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Void> delete(@PathVariable Long id){
        return menuService.delete(id);
    }
    @PostMapping("/updateStatus")
    public Result<Void> updateStatus(@RequestBody @Valid MenuPernUpdateStatusCommand menuPernUpdateStatusCommand){
        return menuService.updateStatus(menuPernUpdateStatusCommand);
    }
}